<?php
namespace app\common\taglib;
use think\template\TagLib;
class Xc extends TagLib{
    /**
     * 定义标签列表
     */
    protected $tags   =  [
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'arctype' => ['attr' => 'name,key,tid,field,limit', 'close' => 1],
        'arclist' => ['attr' => 'name,key,tid,field,order,limit', 'close' => 1],
        'adlist'  => ['attr' => 'name,key,aid,tid,limit', 'close' => 1],
        'flink'   => ['attr' => 'name,key,limit', 'close' => 1],
        
    ];

    
    /**
    * 调用栏目
    * @date: 2018年8月21日 下午6:12:25
    * @author: xiaocui
    * @param: variable
    * @return:
    */
    public function tagArctype($tag, $content){
        $name = $tag['name'];
        $tid = $tag['tid'];
        $key = !empty($tag['key'])?$tag['key']:'i';
        $dfield = 'id,pid,type,dir,title,pic,create_time';
        $field = !empty($tag['field'])?$dfield.','.$tag['field']:$dfield;
        $limit = !empty($tag['limit'])?$tag['limit']:'';
        
        $parse = '';
        $parse .= '<?php $__ARCTYPE__ = \app\common\model\TagData::get_arctype('.$tid.',"'.$field.'","'.$limit.'");?>';
        $parse .= '{volist name="__ARCTYPE__" key="'.$key.'" id="' . $name . '"}';
        $parse .= $content;
        $parse .= '{/volist}';
        return $parse;
    }
    
    /**
    * 调用文章列表
    * @date: 2018年8月22日 上午10:29:46
    * @author: xiaocui
    */
    public function tagArclist($tag, $content) {
        $name = $tag['name'];
        $tid = $tag['tid'];
        $key = !empty($tag['key'])?$tag['key']:'i';
        $dfield = 'id,tid,mid,title,keywords,description,pic,create_time,update_time';
        $field = !empty($tag['field'])?$dfield.','.$tag['field']:$dfield;
        $order = !empty($tag['order'])?$tag['order']:'sort desc,id desc';
        $limit = !empty($tag['limit'])?$tag['limit']:'';
        
        $parse = '';
        $parse .= '<?php $__ARCLIST__ = \app\common\model\TagData::get_arclist('.$tid.',"'.$field.'","'.$order.'","'.$limit.'");?>';
        $parse .= '{volist name="__ARCLIST__" key="'.$key.'" id="' . $name . '"}';
        $parse .= $content;
        $parse .= '{/volist}';
        return $parse;
    }
    
    
    /**
    * 调用广告位
    * @date: 2018年8月22日 下午3:27:24
    * @author: xiaocui
    * @param: variable
    * @return:
    */
    public function tagAdlist($tag, $content){
        $name = $tag['name'];
        $key = !empty($tag['key'])?$tag['key']:'i';
        $tid = !empty($tag['tid'])?intval($tag['tid']):0;
        $aid = !empty($tag['aid'])?intval($tag['aid']):0;
        $limit = !empty($tag['limit'])?$tag['limit']:'';
    
        $parse = '';
        $parse .= '<?php $__ADLIST__ = \app\common\model\TagData::get_adlist('.$aid.','.$tid.',"'.$limit.'");?>';
        $parse .= '{volist name="__ADLIST__" key="'.$key.'" id="' . $name . '"}';
        $parse .= $content;
        $parse .= '{/volist}';
        return $parse;
    }
    
    /**
    * 调用友情链接
    * @date: 2018年8月22日 下午3:58:36
    * @author: xiaocui
    * @param: variable
    * @return:
    */
    public function tagFlink($tag, $content){
        $name = $tag['name'];
        $key = !empty($tag['key'])?$tag['key']:'i';
        $limit = !empty($tag['limit'])?$tag['limit']:'';
        
        $parse = '';
        $parse .= '<?php $__FLINK__ = \app\common\model\TagData::get_flink("'.$limit.'");?>';
        $parse .= '{volist name="__FLINK__" key="'.$key.'" id="' . $name . '"}';
        $parse .= $content;
        $parse .= '{/volist}';
        return $parse;
    } 
   
}